#ifndef ANIMATIONMANAGER_H
#define ANIMATIONMANAGER_H

#include <vector>
#include <map>
#include <utility>
#include <iostream>

#include <wx/event.h>
#include <wx/timer.h>

#include "../include/Bone.h"
#include "../include/BoneState.h"
#include "../include/Config.h"

class FrameManager;
class BoneManager;

class AnimationManager: public wxEvtHandler
{
    public:

        /** Constructor of AnimationManager class
        * @param fps frame per second
        * @param rootBone - sceleton's root bone
        */
        AnimationManager(BoneManager *BoneManager, Config *Config);

        /** Destructor */
        ~AnimationManager();

        /** Calculate and returns Sceleton state, on specified frame number
        * @param unsigned long frameNumber
        * @return calculated Sceleton state
        */
        std::vector<BoneState*>* calculateFrameState(unsigned long frameNumber);

        void showFrame(unsigned long frameNumber);

        void deleteState(unsigned long frameNumber);

        void addState(unsigned long frameNumber);

        /** add specified Sceleton state to map, on specified frame number */
        void addState(unsigned long frameNumber, std::vector<BoneState*>* states);

        /** For checking if sepcified frameNumbers has saved state in map
        * @return ture if states with tihis number is saved
        */
        bool hasState(unsigned long frameNumber);

        /** Returns info of all frames
        * @return frames info
        */
        const std::map< unsigned long, std::vector< BoneState*>* > &getFramesInfo();

        void start();

        /** Plays prepared animation from the given frame
        * @param frame the number of frame, that the animation has to be played from
        */
        void play();

        /** Pauses the animation giving ability, to play it from the stopped frame */
        void pause();

        /** Stops the animation. Next time, when the animation will be played with default value on input it will be played from the beginning. */
        void stop();

    private:

        static const long ID_TIMER;

        void OnTimer(wxTimerEvent& event);

        /** Helps to manage animation */
        wxTimer* timer;

        /** BoneManger */
        BoneManager* boneManager;

        /** Config */
        Config* config;

        unsigned frameNo;

        /** map of frames wtih  pairs (frameId , bonesStates) */
        std::map< unsigned long, std::vector< BoneState*>* > framesInfo;

        DECLARE_EVENT_TABLE()
};

#endif // ANIMATIONMANAGER_H
